import {defineConfig} from 'vite';
import dts from 'vite-plugin-dts';
import Package from './package.json';

const outDir: string = 'dist';

function Capitalize(text: string): string {
    return (text.charAt(0).toUpperCase() + text.slice(1).toLowerCase());
}

function GetLibName(): string {
    try {
        return Package.name.split('-').map(text => Capitalize(text)).join('');
    } catch (err) {
        throw new Error('Name property in package.json is missing.');
    }
}

export default defineConfig({
    build: {
        outDir: outDir,
        minify: false,
        emptyOutDir: true,
        lib: {
            entry: 'lib/index.ts',
            name: GetLibName(),
            fileName: (format, name) => `${name}.${format}.js`
        },
        rollupOptions: {}
    },
    plugins: [
        dts({
            rollupTypes: true,
            tsconfigPath: './tsconfig.json'
        })
    ]
});
